package com.ldp.designpatterns.review.structure.proxy.JdkProxy;

import com.ldp.designpatterns.review.structure.proxy.JdkProxy.proxy.JdkProxy;
import com.ldp.designpatterns.review.structure.proxy.JdkProxy.service.IRentHouse;
import com.ldp.designpatterns.review.structure.proxy.JdkProxy.service.ManRentHouse;
import com.ldp.designpatterns.review.structure.proxy.JdkProxy.service.WomanRentHouse;

import java.lang.reflect.Proxy;

/**
 * @ClassName JdkProxyTest
 * @Description TODO
 * @Author lindipei
 * @Date 2023/10/20 18:34
 */
public class JdkProxyTest {

    public static void main(String[] args) {
        JdkProxy jdkProxy = new JdkProxy(new ManRentHouse());
        IRentHouse rentHouse = (IRentHouse) Proxy.newProxyInstance(jdkProxy.getClass().getClassLoader(), new Class[]{IRentHouse.class}, jdkProxy);
        rentHouse.rentHouse();

        jdkProxy = new JdkProxy(new WomanRentHouse());
        rentHouse = (IRentHouse) Proxy.newProxyInstance(jdkProxy.getClass().getClassLoader(), new Class[]{IRentHouse.class}, jdkProxy);
        rentHouse.rentHouse();
    }
}
